/*
 * @(#) PMWorkPlan.java 2013-7-22 下午2:52:05
 *
 * Copyright 2013 Rockwell Automation, Inc. All rights reserved.
 * Rockwell Automation PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */package com.osi.mes.pm.object;

import java.math.BigDecimal;

import com.datasweep.compatibility.client.ATRow;
import com.datasweep.compatibility.client.Response;
import com.datasweep.compatibility.ui.Time;
import com.osi.mes.constants.IATConstants;
import com.osi.mes.constants.IDateFormatConstants;
import com.osi.mes.pm.constants.IPMConstants;
import com.rockwell.ftpc.framework.common.DateTimeUtils;
import com.rockwell.ftpc.framework.common.StringUtils;

/**
 * 生产计划
 * 对应AT表PMWorkPlan
 * @author Nemo, 2013-7-22 下午2:52:16
 */
public class WorkPlan
{
	ATRow atRow;
	public WorkPlan(ATRow atRow){
		this.atRow = atRow;
		this.comment = (String) atRow.getValue(IATConstants.AT_COLUMN_PM_WORK_PLAN_COMMENT);
		this.importDate = (Time) atRow.getValue(IATConstants.AT_COLUMN_PM_WORK_PLAN_IMPORT_DATE);
		this.isTest = atRow.getValue(IATConstants.AT_COLUMN_PM_WORK_PLAN_IS_TEST) == null? false:(Boolean) atRow.getValue(IATConstants.AT_COLUMN_PM_WORK_PLAN_IS_TEST);
		this.partDescription = (String) atRow.getValue(IATConstants.AT_COLUMN_PM_WORK_PLAN_PART_DESCRIPTION);
		this.plannedDate = (Time) atRow.getValue(IATConstants.AT_COLUMN_PM_WORK_PLAN_PLANNED_DATE);
		this.plannedQty = (Float) atRow.getValue(IATConstants.AT_COLUMN_PM_WORK_PLAN_PLANNED_QTY);
		this.productionLine = (String) atRow.getValue(IATConstants.AT_COLUMN_PM_WORK_PLAN_PRODUCTION_LINE);
		this.sapCode = (String) atRow.getValue(IATConstants.AT_COLUMN_PM_WORK_PLAN_SAP_CODE);
		this.isOrdered = atRow.getValue(IATConstants.AT_COLUMN_PM_WORK_PLAN_IS_ORDERED) == null? false:(Boolean) atRow.getValue(IATConstants.AT_COLUMN_PM_WORK_PLAN_IS_ORDERED);
		this.orderNumber = atRow.getValue(IATConstants.AT_COLUMN_PM_WORK_PLAN_ORDER_NUMBER) == null? null:atRow.getValue(IATConstants.AT_COLUMN_PM_WORK_PLAN_ORDER_NUMBER).toString();
	}
	
	String comment;
	Time importDate;
	Boolean isTest;
	String partDescription;
	Time plannedDate;
	Float plannedQty;
	String productionLine;
	String sapCode;
	Boolean isOrdered;
	String orderNumber;
	
	public String getComment()
	{
		return comment;
	}
	public String getImportDate()
	{
		return DateTimeUtils.formatDate(importDate, IDateFormatConstants.DATE_TIME_FORMAT_DAY);
	}
	public String getIsTest()
	{
		return isTest?IPMConstants.WORK_PLAN_IS_TEST_TRUE:IPMConstants.WORK_PLAN_IS_TEST_FALSE;
	}
	public String getPartDescription()
	{
		return partDescription;
	}
	public String getPlannedDate()
	{
		return DateTimeUtils.formatDate(plannedDate, IDateFormatConstants.DATE_TIME_FORMAT_DAY);
	}
	public BigDecimal getPlannedQty()
	{
		return new BigDecimal(plannedQty).setScale(2, 3);
	}
	public String getProductionLine()
	{
		return productionLine;
	}
	public String getSapCode()
	{
		return sapCode;
	}
	
	public String getIsOrdered()
	{
		return isOrdered?IPMConstants.WORK_PLAN_IS_TEST_TRUE:IPMConstants.WORK_PLAN_IS_TEST_FALSE;
	}
	
	public Boolean isOrdered()
	{
		return isOrdered;
	}
	
	public ATRow getObject()
	{
		return atRow;
	}
	
	public String getOrderNumber()
	{
		return orderNumber;
	}
	
	public Response markOrdered(String orderNumber)
	{
		atRow.setValue(IATConstants.AT_COLUMN_PM_WORK_PLAN_IS_ORDERED, true);
		atRow.setValue(IATConstants.AT_COLUMN_PM_WORK_PLAN_ORDER_NUMBER,orderNumber);
		return atRow.save(null, null, null);
	}
}
